package com.toolsDemo.importDemo.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.toolsDemo.importDemo.dao.ExcelImportMapper;
import com.toolsDemo.importDemo.po.DemoPO;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class DemoListener extends AnalysisEventListener<DemoPO> {

    @Autowired
    private ExcelImportMapper excelImportMapper;

    private static List<DemoPO> demoPOList;

    @Override
    public void invoke(DemoPO demoPO, AnalysisContext analysisContext) {
        System.out.println(demoPO.toString());
        demoPOList.add(demoPO);
        addDemoPOList();
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        excelImportMapper.addUser(demoPOList);
    }

    private void addData(DemoPO demoPO){
        addDemoPOList();
        demoPOList.clear();
    }

    public List<DemoPO> getDemoPOList() {
        return demoPOList;
    }

    public void addDemoPOList() {
        excelImportMapper.addUser(demoPOList);
    }


}
